package com.hanrui.android.utils;

import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.Build;
import android.support.v4.content.FileProvider;
import android.util.Log;

import com.blankj.utilcode.util.IntentUtils;
import com.blankj.utilcode.util.SPUtils;
import com.blankj.utilcode.util.StringUtils;
import com.blankj.utilcode.util.ToastUtils;
import com.hanrui.android.BuildConfig;
import com.hanrui.android.R;
import com.hanrui.android.constant.Constant;
import com.hanrui.android.model.CheckBean;
import com.hanrui.android.model.User;

import org.apache.commons.codec.binary.Base64;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.StreamCorruptedException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
 * Created by Administrator on 2018/3/9.
 */

public class BaseUtils {

    /**
     * 登录缓存
     *
     * @param context
     * @param user
     */
    public static void saveUser(Context context, User user) {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        try {
            ObjectOutputStream oos = new ObjectOutputStream(baos);
            oos.writeObject(user);
            String str = new String(Base64.encodeBase64(baos.toByteArray()));
            SPUtils.getInstance(Constant.USER_NAME).put(Constant.USER_KEY, str);
            oos.close();
            baos.close();
        } catch (IOException e) {
            e.printStackTrace();
            Log.e(Constant.tag, "缓存失败");
        }

        Log.e(Constant.tag, "缓存成功");
        //MainActivity.start();
    }

    /**
     * 获取登录缓存
     *
     * @param context
     * @return
     */
    public static User getUser(Context context) {
        User user = null;
        String str = SPUtils.getInstance(Constant.USER_NAME).getString(Constant.USER_KEY);
        if (str == null) {
            return null;
        }
        byte[] byte_str = Base64.decodeBase64(str.getBytes());
        ByteArrayInputStream bais = new ByteArrayInputStream(byte_str);
        try {
            ObjectInputStream ois = new ObjectInputStream(bais);
            user = (User) ois.readObject();
            ois.close();
            bais.close();

        } catch (StreamCorruptedException e) {
            e.printStackTrace();
            Log.i("缓存", "缓存失败");
        } catch (IOException e) {
            e.printStackTrace();
            Log.i("缓存", "缓存失败");
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
            Log.i("缓存", "缓存失败");
        }
        return user;
    }


    public static Map<String, String> getData(List<CheckBean> list) {
        Map<String, String> map = new HashMap<>();
        int count = 0;
        String id = "";
        String data = "";
        StringBuffer buffer = new StringBuffer();
        StringBuffer b = new StringBuffer();
        for (CheckBean bean : list) {
            if (bean.ischeck()) {
                buffer.append(bean.getContent() + ",");
                b.append(bean.getId() + ",");
                count++;
            }
        }
        if (null != buffer && buffer.length() > 0) {
            data = buffer.substring(0, buffer.length() - 1);
        }
        if (null != b && b.length() > 0) {
            id = b.substring(0, b.length() - 1);
        }
        map.put("data", data);
        map.put("id", id);
        map.put("count", count + "");
        return map;
    }

    public static int compareDate(String day1, String day2) {
        int i = 0;
        //将字符串格式的日期格式化
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
        try {
            //将日期转成Date对象作比较
            Date fomatDate1 = sdf.parse(day1);
            Date fomatDate2 = sdf.parse(day2);
            //比较两个日期
            int result = fomatDate2.compareTo(fomatDate1);
            //如果日期相等返回0
            if (result == 0) {
                i = 1;
            } else if (result < 0) {
                //小于0，参数date1就是在date2之后
                i = 2;
            } else {
                //大于0，参数date1就是在date2之前
                i = 3;
            }

        } catch (ParseException e) {

            e.printStackTrace();
        }

        return i;
    }


    /**
     * 获取版本号
     * @return 当前应用的版本号
     */
    public static String getVersionName(Context context) {

        try {

            PackageManager packageManager = context.getPackageManager();
            PackageInfo info = packageManager.getPackageInfo(context.getPackageName(), 0);
            String currentVersion = info.versionName;
            return currentVersion;

        } catch (Exception e) {

            e.printStackTrace();
            return "";

        }
    }

//    public static String getAuditIds(List<GetNextActvity.NextActivityBean.NextAssigneeListBean> list) {
//        String data = "";
//        StringBuffer buffer = new StringBuffer();
//        for (GetNextActvity.NextActivityBean.NextAssigneeListBean bean : list) {
//            buffer.append(bean.getId() + ",");
//        }
//        if (null != buffer && buffer.length() > 0) {
//            data = buffer.substring(0, buffer.length() - 1);
//        }
//        return data;
//    }


    public static int timeBefore(String a, String b) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        Date bt = null;
        Date et = null;
        try {
            bt = sdf.parse(a);
            et = sdf.parse(b);
        } catch (Exception e) {
            return 1;
        }
        if ((bt.getTime() - et.getTime()) > 0) {
            return 0;
        } else {
            return 1;
        }
    }


    public static int getImage(String name) {
        int i = R.mipmap.hy1;
        switch (name) {
            case "会议申请":
                i = R.mipmap.hy1;
                break;
            case "我的会议":
                i = R.mipmap.hy2;
                break;
            case "会议查看":
                i = R.mipmap.hy3;
                break;
            case "周会督办":
                i = R.mipmap.db1;
                break;
            case "月会督办":
                i = R.mipmap.db2;
                break;
            case "三色督办":
                i = R.mipmap.db3;
                break;
            case "我的督办":
                i = R.mipmap.db4;
                break;
            case "我的文档":
                i = R.mipmap.wd1;
                break;
            case "文档查阅":
                i = R.mipmap.wd2;
                break;
            case "董事会会议":
                i = R.mipmap.dsh1;
                break;
            case "绩效填报":
                i = R.mipmap.jx1;
                break;
            case "我的绩效":
                i = R.mipmap.jx2;
                break;
            case "绩效查看":
                i = R.mipmap.jx3;
                break;
            case "我的档案":
                i = R.mipmap.da1;
                break;
            case "档案查看":
                i = R.mipmap.da2;
                break;
        }
        return i;
    }


    public static boolean fileIsExists(File file) {
        try {
            if (!file.exists()) {
                return false;
            }
        } catch (Exception e) {
            return false;
        }
        return true;
    }


    //android获取一个用于打开HTML文件的intent
    public static Intent getHtmlFileIntent(File file) {
        Uri uri = Uri.parse(file.toString()).buildUpon().encodedAuthority("com.android.htmlfileprovider").scheme("content").encodedPath(file.toString()).build();
        Intent intent = new Intent("android.intent.action.VIEW");
        intent.setDataAndType(uri, "text/html");
        return intent;
    }

    //android获取一个用于打开图片文件的intent
    public static Intent getImageFileIntent(Context mContext,File file) {
        Intent intent = new Intent("android.intent.action.VIEW");
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
            intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
            Uri contentUri = FileProvider.getUriForFile(mContext, BuildConfig.APPLICATION_ID + ".fileProvider", file);
            intent.setDataAndType(contentUri, "image/*");
        } else {
            intent.setDataAndType(Uri.fromFile(file), "image/*");
            //intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        }
//        intent.addCategory("android.intent.category.DEFAULT");
//        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
//        Uri uri = Uri.fromFile(file);
//        intent.setDataAndType(uri, "image/*");
        return intent;
    }

    //android获取一个用于打开PDF文件的intent
    public static Intent getPdfFileIntent(Context mContext,File file) {
        Intent intent = new Intent("android.intent.action.VIEW");
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
            intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
            Uri contentUri = FileProvider.getUriForFile(mContext, BuildConfig.APPLICATION_ID + ".fileProvider", file);
            intent.setDataAndType(contentUri, "application/pdf");
        } else {
            intent.setDataAndType(Uri.fromFile(file), "application/pdf");
        }
//        intent.addCategory("android.intent.category.DEFAULT");
//        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
//        Uri uri = Uri.fromFile(file);
//        intent.setDataAndType(uri, "application/pdf");
        return intent;
    }

    //android获取一个用于打开文本文件的intent
    public static Intent getTextFileIntent(Context mContext,File file) {
        Intent intent = new Intent("android.intent.action.VIEW");
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
            intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
            Uri contentUri = FileProvider.getUriForFile(mContext, BuildConfig.APPLICATION_ID + ".fileProvider", file);
            intent.setDataAndType(contentUri, "text/plain");
        } else {
            intent.setDataAndType(Uri.fromFile(file), "text/plain");
        }
//        intent.addCategory("android.intent.category.DEFAULT");
//        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
//        Uri uri = Uri.fromFile(file);
//        intent.setDataAndType(uri, "text/plain");
        return intent;
    }

    //android获取一个用于打开音频文件的intent
    public static Intent getAudioFileIntent(Context mContext,File file) {
        Intent intent = new Intent("android.intent.action.VIEW");
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
            intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
            Uri contentUri = FileProvider.getUriForFile(mContext, BuildConfig.APPLICATION_ID + ".fileProvider", file);
            intent.setDataAndType(contentUri, "audio/*");
        } else {
            intent.setDataAndType(Uri.fromFile(file), "audio/*");
        }
//        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
//        intent.putExtra("oneshot", 0);
//        intent.putExtra("configchange", 0);
//        Uri uri = Uri.fromFile(file);
//        intent.setDataAndType(uri, "audio/*");
        return intent;
    }

    //android获取一个用于打开视频文件的intent
    public static Intent getVideoFileIntent(Context mContext,File file) {
        Intent intent = new Intent("android.intent.action.VIEW");
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
//        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
//        intent.putExtra("oneshot", 0);
//        intent.putExtra("configchange", 0);
//        Uri uri = Uri.fromFile(file);
//        intent.setDataAndType(uri, "video/*");
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
            intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
            Uri contentUri = FileProvider.getUriForFile(mContext, BuildConfig.APPLICATION_ID + ".fileProvider", file);
            intent.setDataAndType(contentUri, "video/*");
        } else {
            intent.setDataAndType(Uri.fromFile(file), "video/*");
        }
        return intent;
    }


    //android获取一个用于打开CHM文件的intent
    public static Intent getChmFileIntent(Context mContext,File file) {
        Intent intent = new Intent("android.intent.action.VIEW");
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
//        intent.addCategory("android.intent.category.DEFAULT");
//        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
//        Uri uri = Uri.fromFile(file);
//        intent.setDataAndType(uri, "application/x-chm");
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
            intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
            Uri contentUri = FileProvider.getUriForFile(mContext, BuildConfig.APPLICATION_ID + ".fileProvider", file);
            intent.setDataAndType(contentUri, "application/x-chm");
        } else {
            intent.setDataAndType(Uri.fromFile(file), "application/x-chm");
        }
        return intent;
    }


    //android获取一个用于打开Word文件的intent
    public static Intent getWordFileIntent(Context mContext,File file) {
        Intent intent = new Intent("android.intent.action.VIEW");
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
            intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
            Log.e(Constant.tag,BuildConfig.APPLICATION_ID);
            Uri contentUri = FileProvider.getUriForFile(mContext, BuildConfig.APPLICATION_ID + ".fileProvider", file);
            intent.setDataAndType(contentUri, "application/msword");
        } else {
            intent.setDataAndType(Uri.fromFile(file), "application/msword");
        }
//        intent.addCategory("android.intent.category.DEFAULT");
//        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
//        Uri uri = Uri.fromFile(file);
//        intent.setDataAndType(uri, "application/msword");
        return intent;
    }

    //android获取一个用于打开Excel文件的intent
    public static Intent getExcelFileIntent(Context mContext,File file) {
        Intent intent = new Intent("android.intent.action.VIEW");
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
            intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
            Uri contentUri = FileProvider.getUriForFile(mContext, BuildConfig.APPLICATION_ID + ".fileProvider", file);
            intent.setDataAndType(contentUri, "application/vnd.ms-excel");
        } else {
            intent.setDataAndType(Uri.fromFile(file), "application/vnd.ms-excel");
        }
//        intent.addCategory("android.intent.category.DEFAULT");
//        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
//        Uri uri = Uri.fromFile(file);
//        intent.setDataAndType(uri, "application/vnd.ms-excel");
        return intent;
    }

    //android获取一个用于打开PPT文件的intent
    public static Intent getPPTFileIntent(Context mContext,File file) {
        Intent intent = new Intent("android.intent.action.VIEW");
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
            intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
            Uri contentUri = FileProvider.getUriForFile(mContext, BuildConfig.APPLICATION_ID + ".fileProvider", file);
            intent.setDataAndType(contentUri, "application/vnd.ms-powerpoint");
        } else {
            intent.setDataAndType(Uri.fromFile(file), "application/vnd.ms-powerpoint");
        }
        return intent;
    }

    //android获取一个用于打开apk文件的intent
    public static Intent getApkFileIntent(Context mContext,File file) {
        Intent intent = new Intent();
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
            intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
            Uri contentUri = FileProvider.getUriForFile(mContext, BuildConfig.APPLICATION_ID + ".fileProvider", file);
            intent.setDataAndType(contentUri, "application/vnd.android.package-archive");
        } else {
            intent.setDataAndType(Uri.fromFile(file), "application/vnd.android.package-archive");
        }
//        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
//        intent.setAction(android.content.Intent.ACTION_VIEW);
//        intent.setDataAndType(Uri.fromFile(file), "application/vnd.android.package-archive");
        return intent;
    }


    private static boolean checkEndsWithInStringArray(String checkItsEnd,
                                                      String[] fileEndings) {
        for (String aEnd : fileEndings) {
            if (checkItsEnd.endsWith(aEnd))
                return true;
        }
        return false;
    }


    public static void goFileOpne(Context mContext,File currentPath) {
        if (currentPath != null && currentPath.isFile()) {
            String fileName = currentPath.toString();
            Intent intent = null;
            if (checkEndsWithInStringArray(fileName, mContext.getResources().
                    getStringArray(R.array.fileEndingImage))) {
                intent = getImageFileIntent(mContext,currentPath);
            } else if (checkEndsWithInStringArray(fileName, mContext.getResources().
                    getStringArray(R.array.fileEndingWebText))) {
                intent = getHtmlFileIntent(currentPath);
            } else if (checkEndsWithInStringArray(fileName, mContext.getResources().
                    getStringArray(R.array.fileEndingPackage))) {
                intent = getApkFileIntent(mContext,currentPath);
            } else if (checkEndsWithInStringArray(fileName, mContext.getResources().
                    getStringArray(R.array.fileEndingAudio))) {
                intent = getAudioFileIntent(mContext,currentPath);
            } else if (checkEndsWithInStringArray(fileName, mContext.getResources().
                    getStringArray(R.array.fileEndingVideo))) {
                intent = getVideoFileIntent(mContext,currentPath);
            } else if (checkEndsWithInStringArray(fileName, mContext.getResources().
                    getStringArray(R.array.fileEndingText))) {
                intent = getTextFileIntent(mContext,currentPath);
            } else if (checkEndsWithInStringArray(fileName, mContext.getResources().
                    getStringArray(R.array.fileEndingPdf))) {
                intent = getPdfFileIntent(mContext,currentPath);
            } else if (checkEndsWithInStringArray(fileName, mContext.getResources().
                    getStringArray(R.array.fileEndingWord))) {
                intent = getWordFileIntent(mContext,currentPath);
            } else if (checkEndsWithInStringArray(fileName, mContext.getResources().
                    getStringArray(R.array.fileEndingExcel))) {
                intent = getExcelFileIntent(mContext,currentPath);
            } else if (checkEndsWithInStringArray(fileName, mContext.getResources().
                    getStringArray(R.array.fileEndingPPT))) {
                intent = getPPTFileIntent(mContext,currentPath);
            }

            if (IntentUtils.isIntentAvailable(intent)) {
                mContext.startActivity(intent);
            }else {
                ToastUtils.showShort("无法打开，请安装对应的应用！");
            }

        } else {
            ToastUtils.showShort("对不起，这不是文件！");
        }
    }


    public static long daysBetween(Date one, Date two) {
        long difference = (one.getTime() - two.getTime()) / 86400000;
        return Math.abs(difference);
    }

    public static Date getMonthStartDate(int year, int month) {
        Calendar cal = Calendar.getInstance();
        // 不加下面2行，就是取当前时间前一个月的第一天及最后一天
        cal.set(Calendar.YEAR, year);
        cal.set(Calendar.MONTH, month - 1);
        cal.set(Calendar.DAY_OF_MONTH, 1);
//        cal.add(Calendar.DAY_OF_MONTH, -1);
//        Date lastDate = cal.getTime();
//
//        cal.set(Calendar.DAY_OF_MONTH, 1);
        Date firstDate = cal.getTime();
        return firstDate;
    }

    public static Date getMonthEndDate(int year, int month) {
        Calendar cal = Calendar.getInstance();
        // 不加下面2行，就是取当前时间前一个月的第一天及最后一天
        cal.set(Calendar.YEAR, year);
        cal.set(Calendar.MONTH, month);
        cal.set(Calendar.DAY_OF_MONTH, 1);
        cal.add(Calendar.DAY_OF_MONTH, -1);
        Date lastDate = cal.getTime();

//        cal.set(Calendar.DAY_OF_MONTH, 1);
//        Date firstDate = cal.getTime();
        return lastDate;
    }


    /**
     * 获得该月第一天
     *
     * @param year
     * @param month
     * @return
     */
    public static String getFirstDayOfMonth(int year, int month) {
        Calendar cal = Calendar.getInstance();
        //设置年份
        cal.set(Calendar.YEAR, year);
        //设置月份
        cal.set(Calendar.MONTH, month - 1);
        //获取某月最小天数
        int firstDay = cal.getActualMinimum(Calendar.DAY_OF_MONTH);
        //设置日历中月份的最小天数
        cal.set(Calendar.DAY_OF_MONTH, firstDay);
        //格式化日期
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        String firstDayOfMonth = sdf.format(cal.getTime());
        return firstDayOfMonth;
    }

    /**
     * 获得该月最后一天
     *
     * @param year
     * @param month
     * @return
     */
    public static String getLastDayOfMonth(int year, int month) {
        Calendar cal = Calendar.getInstance();
        //设置年份
        cal.set(Calendar.YEAR, year);
        //设置月份
        cal.set(Calendar.MONTH, month - 1);
        //获取某月最大天数
        int lastDay = cal.getActualMaximum(Calendar.DAY_OF_MONTH);
        //设置日历中月份的最大天数
        cal.set(Calendar.DAY_OF_MONTH, lastDay);
        //格式化日期
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        String lastDayOfMonth = sdf.format(cal.getTime());
        return lastDayOfMonth;
    }


    public static Calendar stringToCalender(String dates) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        Date date = null;
        try {
            date = sdf.parse(dates);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        return calendar;
    }


//    public static int getImage(String name) {
//        int i = R.mipmap.w22;
//        switch (name) {
//            case "我的会议":
//                i = R.mipmap.w20;
//                break;
//            case "今日会议":
//                i = R.mipmap.w13;
//                break;
//            case "会议安排":
//                i = R.mipmap.w9;
//                break;
//            case "会议总览":
//                i = R.mipmap.w11;
//                break;
//
//            case "会议申请":
//                i = R.mipmap.w18;
//                break;
//
//            case "用车申请":
//                i = R.mipmap.w22;
//                break;
//            case "车辆安排":
//                i = R.mipmap.w2;
//                break;
//            case "车辆维保申请":
//                i = R.mipmap.w3;
//                break;
//            case "油卡充值申请":
//                i = R.mipmap.w23;
//                break;
//            case "加油申请":
//                i = R.mipmap.w12;
//                break;
//            case "我的用车":
//                i = R.mipmap.w4;
//                break;
//            case "今日用车":
//                i = R.mipmap.w14;
//                break;
//            case "驾驶员状态":
//                i = R.mipmap.w5;
//                break;
//
//
//            case "考勤统计":
//                i = R.mipmap.w14;
//                break;
//            case "打卡":
//                i = R.mipmap.w7;
//                break;
//            case "补打卡申请":
//                i = R.mipmap.w1;
//                break;
//            case "出差外勤申请":
//                i = R.mipmap.w6;
//                break;
//            case "请假申请":
//                i = R.mipmap.w16;
//                break;
//            case "销假申请":
//                i = R.mipmap.w21;
//                break;
//
//
//            case "日程查看":
//                i = R.mipmap.w17;
//                break;
//
//            case "日程填报":
//                i = R.mipmap.w18;
//                break;
//
//            case "接待":
//                i = R.mipmap.w19;
//                break;
//
//        }
//        return i;
//    }



    /**
     * 计算两个日期相差的天数
     * @param oldDate
     * @return
     * @author WangLiping
     */
    public static int comparePastDate(String oldDate, String nowDate){
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        Calendar calendar = Calendar.getInstance();
        Date old;
        int day=0;
        try {
            old = sdf.parse(oldDate);
            calendar.setTime(old);
            Long oTime = calendar.getTimeInMillis();

            Date now = sdf.parse(nowDate);
            calendar.setTime(now);
            Long nTime = calendar.getTimeInMillis();

            day=(int) ((nTime - oTime)/(3600F * 1000 * 24));
        } catch (ParseException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return day;
    }


    //金额验证
    public static boolean isNumber(String str){

        if (StringUtils.isEmpty(str)) {return false;}

        Pattern pattern= Pattern.compile("^([1-9]\\d{0,9}|0)([.]?|(\\.\\d{1,2})?)$");
        Matcher match=pattern.matcher(str);
        return match.matches();
    }

}
